#include "CMReceiver.h"

void CMReceiver::OnReceiveData(Tr_ResponseID rId, void* wParam, void* lParam)
{
    switch (rId) {
    case Tr_ResponseID::TrOnRtnDepthMarketData:
    {
        CThostFtdcDepthMarketDataField* pData = reinterpret_cast<CThostFtdcDepthMarketDataField*>(wParam);
        std::cout << pData->UpdateTime << " = " << pData->InstrumentID << " = " << pData->LastPrice << " = " << pData->Turnover << std::endl;
        break;
    }
    case Tr_ResponseID::TrOnRspUserLogin:
    {
        break;
    }
    case Tr_ResponseID::TrOnRspQryTradingAccount:
    {
        CThostFtdcTradingAccountField* pTradingAccount = reinterpret_cast<CThostFtdcTradingAccountField*>(wParam);
        //std::cout << pTradingAccount->AccountID << " = " << pTradingAccount->Available << std::endl;

        break;
    }
    case Tr_ResponseID::TrOnInvestorPositions:
    {

        break;
    }
    case Tr_ResponseID::TrOnRtnOrder:
    {
        CThostFtdcOrderField* pOrder = reinterpret_cast<CThostFtdcOrderField*>(wParam);
        CThostFtdcOrderField Order;
        Order = static_cast<CThostFtdcOrderField>(*pOrder);

        break;
    }
    case Tr_ResponseID::TrOnRtnTrade:
    {
        CThostFtdcTradeField* pTrade = reinterpret_cast<CThostFtdcTradeField*>(wParam);

        break;
    }
    case Tr_ResponseID::TrOnRspQryInstrument:
    {
        CThostFtdcInstrumentField* pInstrument = reinterpret_cast<CThostFtdcInstrumentField*>(wParam);
        bool bIslast = reinterpret_cast<bool>(lParam);
        CThostFtdcInstrumentField Instrument;
        memset(&Instrument, 0, sizeof(Instrument));
        memcpy(&Instrument, pInstrument, sizeof(Instrument));
        //std::cout << "TrOnRspQryInstrument: " << Instrument.InstrumentID << std::endl;
        break;
    }
    case Tr_ResponseID::TrOnRspError:
    {
        CThostFtdcRspInfoField* pRspInfo = reinterpret_cast<CThostFtdcRspInfoField*>(wParam);

        break;
    }
    case Tr_ResponseID::TrOnRspOrderInsert:
    {
        break;
    }
    case Tr_ResponseID::TrOnQuote:
    {
        char *s = reinterpret_cast<char*>(wParam);
        char *dd = reinterpret_cast<char*>(lParam);
        std::cout << dd << std::endl;
        break;
    }
    default:
        break;
    }
}